<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('添加'+${levelTitle}+'管理员')" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-edit" class="form-horizontal" th:object="${user}">
            <h4 class="form-header h4">修改[[${levelTitle}]]管理员</h4>
            <input type="hidden" id="userId" name="userId" th:value="*{userId}">
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">[[${levelTitle}]]：</label>
                        <div class="col-sm-8">
                            <select class="form-control m-b" id="deptId" name="deptId" required th:value="*{deptId}">
                                <option value="">请选择</option>
                                <option th:each="dept : ${deptList}" th:value="${dept.deptId}" th:text="${dept.deptName}" th:selected="${user.deptId==dept.deptId}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">管理员：</label>
                        <div class="col-sm-8">
                            <input name="userName" placeholder="" class="form-control" type="text" maxlength="30" required th:value="*{userName}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">联系方式：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="phonenumber" name="phonenumber" placeholder="" class="form-control" type="text" maxlength="11" required th:value="*{phonenumber}">
                                <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">账号：</label>
                        <div class="col-sm-8">
                            <input id="loginName" name="loginName" placeholder="" class="form-control" type="text" maxlength="30" required th:value="*{loginName}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">密码：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="password" name="originalPwd" placeholder="" class="form-control" type="text" required th:value="*{originalPwd}">
                                <span class="input-group-addon"><i class="fa fa-key"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
      
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
	<th:block th:include="include :: footer" />
	<script>
	    var prefix = ctx + "system/user";
	
        $("#form-user-edit").validate({
        	onkeyup: false,
        	rules:{
        		loginName:{
        			minlength: 2,
        			maxlength: 20,
        			remote: {
                        url: prefix + "/checkLoginNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"loginName": function() {
                                return $.common.trim($("#loginName").val());
                            },
                            "userId": function() {
                                return $.common.trim($("#userId").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		password:{
        			minlength: 5,
        			maxlength: 20
        		}
        		// phonenumber:{
        		// 	isPhone:true,
                //     remote: {
                //         url: prefix + "/checkPhoneUnique",
                //         type: "post",
                //         dataType: "json",
                //         data: {
                //             "phonenumber": function () {
                //                 return $.common.trim($("#phonenumber").val());
                //             },
                //             "userId": function() {
                //                 return $.common.trim($("#userId").val());
                //             }
                //         },
                //         dataFilter: function (data, type) {
                //         	return $.validate.unique(data);
                //         }
                //     }
        		// },
        	},
        	messages: {
                "loginName": {
                    remote: "账号已经存在"
                // },
        		// "phonenumber":{
                // 	remote: "手机号码已经存在"
        		}
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	        	var data = $("#form-user-edit").serializeArray();
	        	var status = 0;
                // var deptId = $("#deptId").find("option:selected").val();
	        	data.push({"name": "status", "value": status});
	        	// data.push({"name": "deptId", "value": deptId});
                console.log(data);
	        	$.operate.saveTab("/jjm/manager/edit", data);
	        }
	    }

    </script>
</body>
</html>